package com.wz.device.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wz.common.utils.text.Convert;
import com.wz.device.entity.BasCargoArea;
import com.wz.device.mapper.BasCargoAreaMapper;
import com.wz.device.service.BasCargoAreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author qiqi
 * @since 2021-10-22
 */
@Service
public class BasCargoAreaServiceImpl extends ServiceImpl<BasCargoAreaMapper, BasCargoArea> implements BasCargoAreaService {

    @Autowired
    private BasCargoAreaMapper basCargoAreaMapper;

    /**
     *  根据条件分页查询设备库房区域列表
     *
     * @param basCargoArea 设备库房区域信息
     * @return
     */
    @Override
    public List<BasCargoArea> selectBasCargoAreaList(BasCargoArea basCargoArea) {
        // 生成数据权限过滤条件
        return basCargoAreaMapper.selectCargoArearList(basCargoArea);
    }


    /**
     * 保存设备库房区域信息
     *
     * @param basCargoArea 设备库房区域信息
     * @return 结果
     */
    @Override
    @Transactional
    public String insertBasCargoArea(BasCargoArea basCargoArea)
    {
        // 新增用户信息
        int rows = 0;
        String result=null;
        try {
            rows = basCargoAreaMapper.insertBasCargoArea(basCargoArea);
            result = "操作成功！";
        } catch (Exception e) {
            e.printStackTrace();
            result = "填写有误！";
        }
        return result;
    }

    /**
     * 通过货区ID查询货区
     *
     * @param cargo_area_id 设备库区ID
     * @return 库区对象信息
     */
    @Override
    public BasCargoArea selectBasCargoAreaById(String cargo_area_id)
    {
        return basCargoAreaMapper.selectBasCargoAreaById(cargo_area_id);
    }


    /**
     * 修改货区信息
     *
     * @param basCargoArea 货区信息
     * @return 结果
     */
    @Override
    @Transactional
    public Integer updateBasCargoArea(BasCargoArea basCargoArea)
    {
        int i = 0;
        try {
             i = basCargoAreaMapper.updateBasCargoArea(basCargoArea);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return i;
    }

    /**
     * 批量删除色号被库区信息
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    @Transactional
    public int deleteCargoAareByIds(String ids)
    {
        int i = 0;
        try {
            String[] cargoAareIds = Convert.toStrArray(ids);
            i = basCargoAreaMapper.deleteCargoAareByIds(cargoAareIds);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return i ;
    }

    /**
     * 设备库区锁定状态修改
     *
     * @param basCargoArea 设备库区信息
     * @return
     */
    @Override
    public int changeLocked(BasCargoArea basCargoArea)
    {
        int i = 0;
        try {
            i = basCargoAreaMapper.updateBasCargoArea(basCargoArea);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return i ;
    }


}
